from tkinter import Button, Label
from tkinter import W,E,N,S

import pyperclip


class CustomButtonPair:

    def __init__(self, win, r, left_text, l_function, right_text, r_function, sticky=W, pady=5):
        """
        一行两个按钮
        :param win:
        :param r:
        :param left_text:
        :param l_function:
        :param right_text:
        :param r_function:
        :param sticky:
        :param pady:
        """
        self.button_root = win
        self.l_button = Button(self.button_root, text=left_text, justify='center', width=22, command=l_function)
        self.l_button.grid(row=r, column=1, columnspan=2, sticky=sticky, pady=pady)
        self.r_button = Button(self.button_root, text=right_text, justify='center', width=22, command=r_function)
        self.r_button.grid(row=r, column=3, columnspan=2, sticky=sticky, pady=pady)

class CustomLabelCopyButtonPair:

    def __init__(self, win, r, right_text, left_text="", c=1, left_cols=3, sticky=W, pady=5, l_justify='left', l_wraplength=300):
        """
        左标签，右复制按钮，点击后将文字复制到系统剪切板
        :param win:
        :param r:
        :param right_text:
        :param left_text:
        :param c:
        :param left_cols:
        :param sticky:
        :param pady:
        :param l_justify:
        :param l_wraplength:
        """
        self.text_button_root = win
        self.left_label = Label(self.text_button_root, text=left_text, wraplength=l_wraplength, justify=l_justify, height=2)
        self.left_label.grid(row=r, column=c, sticky=sticky, columnspan=left_cols)

        self.r_button = Button(self.text_button_root, text=right_text, justify='center', width=10, command=self.copy_path)
        self.r_button.grid(row=r, column=c+left_cols, columnspan=1, sticky=sticky, pady=pady)

    def copy_path(self):
        import os

        from CommonOperations.project_root_path import project_root_path
        from CommonOperations.get_all_configs import get_all_configs

        img_save_dir = get_all_configs()['small_dir']
        project_root = project_root_path()
        img_save_dir_path = os.path.join(project_root, img_save_dir)
        left_text = self.left_label['text']

        full_left_path = os.path.join(img_save_dir_path, left_text)
        pyperclip.copy(full_left_path)
